#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
	cin >> s;
	int n = s.size();
	if (n & 1) {
		n++;
		for (int i = 0; i < n / 2; i++) cout << "4";
		for (int i = 0; i < n / 2; i++) cout << "7";
	}
	else {
		int cnt1 = 0, cnt2 = 0;
		for (int i = 0; i < n; i++) {
			cnt1 += (s[i] == '4');
			cnt2 += (s[i] == '7');
		}
		if (cnt1 == cnt2 && cnt1) {
			cout << s << endl;
			return 0;
		}
		else {
			if (s[0] >= '8') {
				n += 2;
				for (int i = 0; i < n / 2; i++)cout << "4";
				for (int i = 0; i < n / 2; i++)cout << "7";
			}
			else if (s[0] <= '3') {
				for (int i = 0; i < n / 2; i++)cout << "4";
				for (int i = 0; i < n / 2; i++)cout << "7";
			}
			else {
				string temp;
				for (int i = 0; i < n / 2; i++)temp += "7";
				for (int i = 0; i < n / 2; i++)temp += "4";
				if (s > temp) {
					n += 2;
					for (int i = 0; i < n / 2; i++)cout << "4";
					for (int i = 0; i < n / 2; i++)cout << "7";
				}
				else {
					bool flag = 0;
					cnt1 = n / 2;
					cnt2 = n / 2;
					for (int i = 0; i < n; i++) {
						
					}
				}
			}
		}
	}
	return 0;
}